﻿using System;
using NUnit.Framework;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using UserManage;

/// <summary>
/// Summary description for UserManagerNUnit
/// </summary>

[TestFixture]
public class UserManagerNUnit
{
    UserManager _nUnit= new UserManager() ;
   
	public UserManagerNUnit()
	{
		//
		// TODO: Add constructor logic here
		//
    }
    #region "Add User"
    [Test]
    public void AddUser_Test1()
    { 
        UserDetails userAddTest = new UserDetails();
        userAddTest.UserFirstName = string.Empty;
        userAddTest.UserLastName = string.Empty;
        userAddTest.Gender = string.Empty;
        _nUnit.AddUser(userAddTest);
        Assert.Fail("Expected To Fail Because Required Parameters Are Missing");

    }

    [Test]
    public void AddUser_Test2()
    {
        UserDetails userAddTest = new UserDetails();
        userAddTest.UserFirstName = string.Empty;
        userAddTest.UserLastName = "Last";
        userAddTest.Gender = "Male";
        _nUnit.AddUser(userAddTest);
        Assert.Fail("Expected To Fail Because 1st Parameter is Missing");

    }

    [Test]
    public void AddUser_Test3()
    {
        UserDetails userAddTest = new UserDetails();
        userAddTest.UserFirstName = "First";
        userAddTest.UserLastName = string.Empty;
        userAddTest.Gender = "Male";
        _nUnit.AddUser(userAddTest);
        Assert.Fail("Expected To Fail Because 2nd Parameter is Missing");

    }

    [Test]
    public void AddUser_Test4()
    {
        UserDetails userAddTest = new UserDetails();
        userAddTest.UserFirstName = "First";
        userAddTest.UserLastName = "Last";
        userAddTest.Gender = string.Empty;
        _nUnit.AddUser(userAddTest);
        Assert.Fail("Expected To Fail Because 3rd Parameter is Missing");

    }

    [Test]
    public void AddUser_Test5()
    {
        UserDetails userAddTest = new UserDetails();
        userAddTest.UserFirstName = string.Empty;
        userAddTest.UserLastName = string.Empty;
        userAddTest.Gender = "abcdefghijklmno";
        _nUnit.AddUser(userAddTest);
        Assert.Fail("Expected To Fail Because of Invalid Parameter Gender");

    }

    [Test]
    public void AddUser_Test6()
    {
        UserDetails userAddTest = new UserDetails();
        userAddTest.UserFirstName = "First";
        userAddTest.UserLastName = "Last";
        userAddTest.Gender = "Male";
        userAddTest.Phone = "abcd";
        _nUnit.AddUser(userAddTest);
        Assert.Fail("Expected To Fail Because of Invalid Parameter Phone");

    }

    [Test]
    public void AddUser_Test7()
    {
        UserDetails userAddTest = new UserDetails();
        userAddTest.UserFirstName = "First";
        userAddTest.UserLastName = "Last";
        userAddTest.Gender = "Male";
        Assert.IsTrue(_nUnit.AddUser(userAddTest));

    }

    [Test]
    public void AddUser_Test8()
    {
        UserDetails userAddTest = new UserDetails();
        userAddTest.UserFirstName = "First";
        userAddTest.UserLastName = "Last";
        userAddTest.Gender = "Male";
        userAddTest.Phone = "9995909099";
        Assert.IsTrue(_nUnit.AddUser(userAddTest));

    }


    #endregion

    #region "Delete User"
    //[Test]
    //public void DeleteUser_Test1()
    //{
    //    UserDetails userDeleteTest = new UserDetails();
    //    userDeleteTest.UserID = string.Empty;
    //    _nUnit.DeleteUser(userDeleteTest);
    //    Assert.Fail("Expected To Fail Because Parameter UserID is Missing");

    //}

    //[Test]
    //public void DeleteUser_Test2()
    //{
    //    UserDetails userDeleteTest = new UserDetails();
    //    userDeleteTest.UserID = "abcd";
    //    _nUnit.DeleteUser(userDeleteTest);
    //    Assert.Fail("Expected To Fail Because of Invalid Parameter UserID");

    //}

    //[Test]
    //public void DeleteUser_Test3()
    //{
    //    UserDetails userDeleteTest = new UserDetails();
    //    userDeleteTest.UserID = "1";
    //    Assert.IsTrue(_nUnit.DeleteUser(userDeleteTest));

    //}
    #endregion

    #region "Edit User"
   
    [Test]
    public void EditUser_Test1()
    {
        UserDetails userEditTest = new UserDetails();
        _nUnit.EditUser(userEditTest);
        Assert.Fail("Expected To Fail Because Parameter UserID is Missing");

    }

    [Test]
    public void EditUser_Test2()
    {
        UserDetails userEditTest = new UserDetails();
        userEditTest.UserID = "abcd";
        _nUnit.EditUser(userEditTest);
        Assert.Fail("Expected To Fail Because of Invalid Parameter UserID");

    }

   
    [Test]
    public void EditUser_Test3()
    {
        UserDetails userEditTest = new UserDetails();
        userEditTest.UserID = "1";
        userEditTest.Phone = "abcd";
        _nUnit.EditUser(userEditTest);
        Assert.Fail("Expected To Fail Because of Invalid Parameter Phone");

    }

    [Test]
    public void EditUser_Test4()
    {
        UserDetails userEditTest = new UserDetails();
        userEditTest.UserID = "1";
        Assert.IsTrue(_nUnit.EditUser(userEditTest));

    }

    [Test]
    public void EditUser_Test5()
    {
        UserDetails userEditTest = new UserDetails();
        userEditTest.UserID = "1";
        userEditTest.Phone = "9898967676";
        Assert.IsTrue(_nUnit.EditUser(userEditTest));

    }

   
    #endregion

    #region "Search User"
    [Test]
    public void SearchUser_Test1()
    {
        DataSet ds;
        _nUnit.SearchUser("",out ds);
        Assert.Fail("Expected To Fail Because Parameter UserName is Missing");
    }

    [Test]
    public void SearchUser_Test2()
    {
        DataSet ds;
        Assert.IsTrue(_nUnit.SearchUser("Name", out ds));
    }

    #endregion

    #region "AdvancedSearch"
    
    [Test]
    public void AdvancedSearch_Test1()
    {
        DataSet ds;
        SearchCriteria advanceSearch = new SearchCriteria();
        _nUnit.AdvancedUserSearch(advanceSearch, out ds);
        Assert.Fail("Expected To Fail Because Parameters Are Missing");
    }

    [Test]
    public void AdvancedSearch_Test2()
    {
        DataSet ds;
        SearchCriteria advanceSearch = new SearchCriteria();
        advanceSearch.SetCriteria = "FirstName";
        _nUnit.AdvancedUserSearch(advanceSearch, out ds);
        Assert.Fail("Expected To Fail Because Parameters FirstName and Role Are Missing");
    }

    [Test]
    public void AdvancedSearch_Test3()
    {
        DataSet ds;
        SearchCriteria advanceSearch = new SearchCriteria();
        advanceSearch.SetCriteria = "LastName";
        _nUnit.AdvancedUserSearch(advanceSearch, out ds);
        Assert.Fail("Expected To Fail Because Parameters LastName and Role Missing");
    }

    [Test]
    public void AdvancedSearch_Test4()
    {
        DataSet ds;
        SearchCriteria advanceSearch = new SearchCriteria();
        advanceSearch.SetCriteria = "LoginID";
        _nUnit.AdvancedUserSearch(advanceSearch, out ds);
        Assert.Fail("Expected To Fail Because Parameter LoginID is Missing");
    }

    [Test]
    public void AdvancedSearch_Test5()
    {
        DataSet ds;
        SearchCriteria advanceSearch = new SearchCriteria();
        advanceSearch.SetCriteria = "FirstName";
        advanceSearch.CriteriaName = "Name";
        _nUnit.AdvancedUserSearch(advanceSearch, out ds);
        Assert.Fail("Expected To Fail Because Parameter Role is Missing");
    }

    [Test]
    public void AdvancedSearch_Test6()
    {
        DataSet ds;
        SearchCriteria advanceSearch = new SearchCriteria();
        advanceSearch.SetCriteria = "FirstName";
        advanceSearch.Role = "Role";
        _nUnit.AdvancedUserSearch(advanceSearch, out ds);
        Assert.Fail("Expected To Fail Because Parameter Name is Missing");
    }

    [Test]
    public void AdvancedSearch_Test7()
    {
        DataSet ds;
        SearchCriteria advanceSearch = new SearchCriteria();
        advanceSearch.SetCriteria = "LastName";
        advanceSearch.CriteriaName = "Name";
        _nUnit.AdvancedUserSearch(advanceSearch, out ds);
        Assert.Fail("Expected To Fail Because Parameter Role is Missing");
    }

    [Test]
    public void AdvancedSearch_Test8()
    {
        DataSet ds;
        SearchCriteria advanceSearch = new SearchCriteria();
        advanceSearch.SetCriteria = "LastName";
        advanceSearch.Role = "Role";
        _nUnit.AdvancedUserSearch(advanceSearch, out ds);
        Assert.Fail("Expected To Fail Because Parameter Name is Missing");
    }

    [Test]
    public void AdvancedSearch_Test9()
    {
        DataSet ds;
        SearchCriteria advanceSearch = new SearchCriteria();
        advanceSearch.SetCriteria = "FirstName";
        advanceSearch.CriteriaName = "Name";
        advanceSearch.Role = "Role";
        Assert.IsTrue(_nUnit.AdvancedUserSearch(advanceSearch, out ds));
    }

    [Test]
    public void AdvancedSearch_Test10()
    {
        DataSet ds;
        SearchCriteria advanceSearch = new SearchCriteria();
        advanceSearch.SetCriteria = "LastName";
        advanceSearch.CriteriaName = "Name";
        advanceSearch.Role = "Role";
        Assert.IsTrue(_nUnit.AdvancedUserSearch(advanceSearch, out ds));
    }

    [Test]
    public void AdvancedSearch_Test11()
    {
        DataSet ds;
        SearchCriteria advanceSearch = new SearchCriteria();
        advanceSearch.SetCriteria = "LoginID";
        advanceSearch.CriteriaName = "LoginName";
        Assert.IsTrue(_nUnit.AdvancedUserSearch(advanceSearch, out ds));
    }

    #endregion

    #region "Register"

    [Test]
    public void UserRegister_Test1()
    {
        UserDetails userLog = new UserDetails();
        _nUnit.UserRegister(userLog);
        Assert.Fail ("Expected To Fail Because Parameters Are Missing");
    }

    [Test]
    public void UserRegister_Test2()
    {
        UserDetails userLog = new UserDetails();
       
        userLog.UserFirstName = "Name";
        userLog.Password ="Password";
        userLog.AuthenticationQuestion = "Question";
        userLog.AuthenticationAnswer = "Answer";

        _nUnit.UserRegister(userLog);
        Assert.Fail("Expected To Fail Because Parameter UserID is Missing");
    }

    [Test]
    public void UserRegister_Test3()
    {
        UserDetails userLog = new UserDetails();
        userLog.UserID ="1";
        userLog.Password = "Password";
        userLog.AuthenticationQuestion = "Question";
        userLog.AuthenticationAnswer = "Answer";

        _nUnit.UserRegister(userLog);
        Assert.Fail("Expected To Fail Because Parameter Name is Missing");
    }

    [Test]
    public void UserRegister_Test4()
    {
        UserDetails userLog = new UserDetails();
        userLog.UserID = "1";
        userLog.UserFirstName = "Name";
        userLog.AuthenticationQuestion = "Question";
        userLog.AuthenticationAnswer = "Answer";
        _nUnit.UserRegister(userLog);
        Assert.Fail("Expected To Fail Because Parameter Password is Missing");
    }

    [Test]
    public void UserRegister_Test5()
    {
        UserDetails userLog = new UserDetails();
        userLog.UserID = "1";
        userLog.UserFirstName = "Name";
        userLog.Password = "Password";
        userLog.AuthenticationAnswer = "Answer";
        _nUnit.UserRegister(userLog);
        Assert.Fail("Expected To Fail Because Parameter Authentication Question is Missing");
    }

    [Test]
    public void UserRegister_Test6()
    {
        UserDetails userLog = new UserDetails();
        userLog.UserID = "1";
        userLog.UserFirstName = "Name";
        userLog.Password = "Password";
        userLog.AuthenticationQuestion = "Question";
        _nUnit.UserRegister(userLog);
        Assert.Fail("Expected To Fail Because Parameter Authentication Answer is Missing");
    }

    [Test]
    public void UserRegister_Test7()
    {
        UserDetails userLog = new UserDetails();
        userLog.UserID = "abcde";
        userLog.UserFirstName = "Name";
        userLog.Password = "Password";
        userLog.AuthenticationQuestion = "Question";
        userLog.AuthenticationAnswer = "Answer";
        _nUnit.UserRegister(userLog);
        Assert.Fail("Expected To Fail Because Parameter UserID is  Invalid");
    }

    [Test]
    public void UserRegister_Test8()
    {
        UserDetails userLog = new UserDetails();
        userLog.UserID = "1";
        userLog.UserFirstName = "Name";
        userLog.Password = "Password";
        userLog.AuthenticationQuestion = "Question";
        userLog.AuthenticationAnswer = "Answer";
        Assert.IsTrue(_nUnit.UserRegister(userLog));
    }

    #endregion

    #region "AddRole"

    [Test]
    public void AddRole_Test1()
    {
        _nUnit.AddRole("", "");
        Assert.Fail("Expected To Fail Beccause Parameters Are Missing");
    }

    [Test]
    public void AddRole_Test2()
    {
        string role = "Role";
        Assert.IsTrue(_nUnit.AddRole(role, ""));
    }

    #endregion

    #region "Search Role"

    [Test]
    public void SearchRole_Test1()
    {
        DataSet ds;
        _nUnit.RoleSearch("",out ds);
        Assert.Fail("Expected To Fail Because Parameters Are Missing");
    }


    [Test]
    public void SearchRole_Test2()
    {
        DataSet ds;
        string role = "RoleName";
        Assert.IsTrue(_nUnit.RoleSearch(role, out ds));
    }

    #endregion

    #region "Edit Role"

    [Test]
    public void EditRole_Test1()
    {
        DataSet ds;
        UserRoles roleModify = new UserRoles();
        _nUnit.RoleEdit(roleModify);
        Assert.Fail("Expected To Fail Because Parameters Are Missing");
    }


    [Test]
    public void EditRole_Test2()
    {
        DataSet ds;
        UserRoles roleModify = new UserRoles();
        roleModify.RoleName = "Role";
        roleModify.RoleDescription = "Description";
        _nUnit.RoleEdit(roleModify);
        Assert.Fail("Expected To Fail Because RoleID is Missing");
    }

    [Test]
    public void EditRole_Test3()
    {
        DataSet ds;
        UserRoles roleModify = new UserRoles();
        roleModify.RoleID = "1";
        roleModify.RoleDescription = "Description";
        _nUnit.RoleEdit(roleModify);
        Assert.Fail("Expected To Fail Because Role is Missing");
    }

    [Test]
    public void EditRole_Test4()
    {
        DataSet ds;
        UserRoles roleModify = new UserRoles();
        roleModify.RoleID = "1";
        roleModify.RoleName = "Role";
        roleModify.RoleDescription = "Description";
        Assert.IsTrue(_nUnit.RoleEdit(roleModify));
    }

    #endregion
}
